#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>

#define lld long long // long long 的printf 占位符是lld
#define ENDL '\n'     // 将 endl 替换为 \n 取消缓冲区

const long long MAX_ = 1e9;

using std::cin;
using std::cout;
using std::string;
int A[10009], B[10009], num[10009];
void solve() {
  //
  std::memset(B, 0, sizeof(B));
  std::memset(A, 0, sizeof(A));
  std::memset(num, 0, sizeof(num));
  int n;
  int sum = 0; // sum 走完所有点
  cin >> n;
  for (size_t i = 0; i < n; ++i)
    cin >> num[i], sum += num[i];

  for (size_t i = 1; i < n; ++i) {
    // A[i]顺时针走到i的step A[0]=0
    // B[i]逆时针走到i的step B[0]=0
    A[i] = A[i - 1] + num[i - 1];
    B[i] = B[i - 1] + num[n - i];
  }

  int min_ = 1e9;
  for (int i = 0; i < n; ++i)
    //
    min_ = std::min(min_, sum - num[i] + A[i]);

  for (int i = n - 1; i >= 0; --i)
    min_ = std::min(min_, sum - num[i] + B[n - i - 1]);
  cout << min_ << ENDL;
}
int main() {
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
}